home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
151-175
/
scopedisk168
/
clianywhere
/
openscreen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-19
|
8KB
|
300 lines
;/*
FailAt 1
LC -M -v -iINCLUDE:CompactH/ OpenScreen.c
Blink lib:c.o OpenScreen.o LIB lib:lc.lib SC SD ND
Quit
CLPs
-t$ Title text
-w# Width
-h# Height
-d# Depth
-c#,#,... Colors (in HEX, comma delimited, blank uses default)
-e# top Edge
-1# pen 1 (DetailPen)
-2# pen 2 (BlockPen)
-H HIRES on
-L HIRES off (Lowres)
-I LACE on (Interlace)
-N LACE off (No interlace)
-B SCREENBEHIND on
*/
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <ctype.h>
#include <intuition/intuition.h>
#include <exec/memory.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#define skip_white(p) while(isspace(*(p))) (p)++
struct NewScreen ns = {0,0,0,0,0,0,0,0,WBENCHSCREEN,NULL,NULL,NULL,NULL};
struct Screen wb;
UWORD colors[32];
byte custom_palette = 0;
short hex_val(char x)
{
if (!isxdigit(x)) return(-1);
if (isalpha(x))
{
return( (short)( toupper((short)x) - (short)'A' + (short)10 ) );
}
return( (short)( (short)x - (short)'0' ) );
}
void set_colors(char *c)
{
short dgtcnt;
short num[3];
short color;
short reg;
short val;
for(reg = 0; (*c) && (reg < 32);)
{
skip_white(c);
if (!*c) break;
if (*c == ',')
{
color = GetRGB4(wb.ViewPort.ColorMap,reg);
}
else
{
for(dgtcnt = 0; (dgtcnt<3) && (*c) && (*c != ',') && (!isspace(*c));)
{
num[dgtcnt] = hex_val(*c);
if (num[dgtcnt] == -1)
{
printf("illegal digit in colors arg\n");
return;
}
c++;
dgtcnt++;
}
skip_white(c);
if ( (dgtcnt > 3) || ( (*c) && (*c != ',') ) )
{
printf("illegal value in colors arg\n");
return;
}
for(val = 1, color = 0; dgtcnt > 0; dgtcnt--, val *= 16)
{
color += (num[dgtcnt-1] * val);
}
}
colors[reg] = color;
reg++;
if (*c == ',') c++;
}
if (reg < 32)
{
for(; reg < 32; reg++)
{
colors[reg] = GetRGB4(wb.ViewPort.ColorMap,reg);
}
}
custom_palette = 1;
}
void usage(void)
{
char *msg =
"CLI Usage: OpenScreen [switches]\n\
\nValid switches are: ('$' equals string data; '#' = numeric data)\n\
-t$ set screen Title text\n\
-w# set screen Width\n\
-h# set screen Height\n\
-d# set screen Depth (number of bitplanes)\n\
-c#,#,... set screen Colors (in HEX, comma delimited)\n\
-e# set screen initial top Edge\n\
-1# set screen pen 1 (DetailPen)\n\
-2# set screen pen 2 (BlockPen)\n\
-H set Hi-res on\n\
-L set Lo-res on\n\
-I set Interlace on\n\
-N set interlace off\n\
-B open screen Behind all others\n\
\n\
Options that are not specified use defaults. All defaults are\n\
taken from the Workbench screen. Note that the Colors\n\
option (-c) requires numeric data to be in hexadecimal\n\
notation. You may get the proper hex values from the\n\
\"palette\" program found on the Workbench Extras disk.\n\
The color values are listed in order from color 0 through\n\
color N (the number of colors that the screen will use).\n\
Individual color values that are unspecified use Workbench\n\
defaults. If any option requires space character(s) in it the\n\
whole option MUST be enclosed in double-quotes (actually, the\n\
only option which this should effect is 'set Title text' (-t).\n\
Screen type is always set to WBENCHSCREEN, otherwise it\n\
would be unusable.\n\
\n";
printf("%s",msg);
exit(5);
}
main(int argc, char *argv[])
{
struct Screen *s;
int len, cnt, rc=0;
char *name, *c;
if (argc == 0) exit(0); /* real programs don't do Workbench :) */
printf("\nOpenScreen v1.0 -- by Ray Lambert\n\n");
IntuitionBase = (struct IntuitonBase *)OpenLibrary("intuition.library",33L);
if (!IntuitionBase)
{
printf("Can't open IntuitionBase!\n\n");
exit(20);
}
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",33L);
if (!GfxBase)
{
printf("Can't open GfxBase!\n\n");
rc = 20;
goto xit;
}
/*
** get default Workbench stuff
*/
GetScreenData((char *)&wb,sizeof(struct Screen),WBENCHSCREEN,NULL);
ns.Width = wb.ViewPort.DWidth;
ns.Height = wb.ViewPort.DHeight;
ns.Depth = wb.BitMap.Depth;
ns.DetailPen = wb.DetailPen;
ns.BlockPen = wb.BlockPen;
ns.ViewModes = (wb.ViewPort.Modes & (HIRES|LACE));
ns.Type = (wb.Flags & SCREENTYPE);
/*
** scan command line
*/
for(cnt = 1; cnt < argc; cnt++)
{
if (argv[cnt][0] == '-')
{
c = &argv[cnt][2];
switch(argv[cnt][1])
{
case 't': /* Title text */
{
len = (strlen(c) + 1);
name = AllocMem(len,NULL);
if (name)
{
strcpy(name,c);
ns.DefaultTitle = (UBYTE *)name;
}
continue;
}
case 'w': /* Width */
{
ns.Width = atoi(c);
continue;
}
case 'h': /* Height */
{
ns.Height = atoi(c);
continue;
}
case 'd': /* Depth */
{
ns.Depth = atoi(c);
continue;
}
case 'c': /* Colors */
{
set_colors(c);
continue;
}
case 'e': /* top Edge */
{
ns.TopEdge = atoi(c);
continue;
}
case '1': /* pen 1 (DetailPen) */
{
ns.DetailPen = atoi(c);
continue;
}
case '2': /* pen 2 (BlockPen) */
{
ns.BlockPen = atoi(c);
continue;
}
case 'H': /* HIRES on */
{
ns.ViewModes |= HIRES;
continue;
}
case 'L': /* HIRES off (Low-res) */
{
ns.ViewModes &= (~HIRES);
continue;
}
case 'I': /* LACE on (Interlace) */
{
ns.ViewModes |= LACE;
continue;
}
case 'N': /* LACE off (No interlace) */
{
ns.ViewModes &= (~LACE);
continue;
}
case 'B': /* SCREENBEHIND on */
{
ns.Type |= SCREENBEHIND;
continue;
}
}
}
else
{
if (strcmp(argv[cnt],"?") == 0) usage();
}
printf("unknown command line option: \"%s\"\n",argv[cnt]);
}
/*
** open the screen
*/
s = OpenScreen(&ns);
if (!s)
{
printf("unable to open your screen\n\n");
rc = 20;
goto xit;
}
/*
** use custom colors (if specified)
*/
if (custom_palette == 1)
{
LoadRGB4(&s->ViewPort,colors,32);
}
printf("screen opened okay\n\n");
xit:
CloseLibrary((struct Library *)IntuitionBase);
CloseLibrary((struct Library *)GfxBase);
exit(rc);
}